﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using System.Windows;

namespace WpfHero
{
    public class GemModel: DependencyObject, INotifyPropertyChanged
    {
        public DateTime CreatedAt { get; private set; }
        public DateTime? FinishedAt { get; private set; }
        public DateTime? RemoveAt { get; private set; }
        public TimeSpan StartAt { get; set; }
        public TimeSpan? EndAt { get; set; }

        public int Button { get; set; }
        public GemModel Previous { get; set; }

        public GemModel()
        {
            CreatedAt = DateTime.Now;
        }

        public void EndNow()
        {
            FinishedAt = DateTime.Now;
            RemoveAt = DateTime.Now + TimeSpan.FromSeconds(5);
            
            if (PropertyChanged != null)
                PropertyChanged(this, new PropertyChangedEventArgs("AsString"));

        }

        public override string ToString()
        {
            return new string(' ', Button) + "X" + new string(' ', 8 - Button) + StartAt + " - " + EndAt ?? "";
        }

        public string AsString
        {
            get { return ToString(); }
        }

        public GemStatus Status
        {
            get { return (GemStatus)GetValue(StatusProperty); }
            set { SetValue(StatusProperty, value); }
        }

        // Using a DependencyProperty as the backing store for Status.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty StatusProperty =
            DependencyProperty.Register("Status", typeof(GemStatus), typeof(GemModel), new UIPropertyMetadata(GemStatus.Coming));



        #region INotifyPropertyChanged Members

        public event PropertyChangedEventHandler PropertyChanged;

        #endregion
    }


    public enum GemStatus
    {
        Coming,
        Current,
        Missed,
        Hit
    }
}
